package com.sanzang;

import com.sanzang.dao.StudentDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class HelloMybatis {

    public static void main(String[] args) {


        try {
            //读配置文件 建立工厂
            InputStream input = Resources.getResourceAsStream("mybatis-config.xml");
            SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
            SqlSessionFactory factory = builder.build(input);

            // 用工厂建立 session 对象
            SqlSession session = factory.openSession();
            // session 创建接口的代理对象
            StudentDao stuDao = session.getMapper(StudentDao.class);
            List list =  stuDao.getStudents();
            System.out.println( list );

            session.close();
            input.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
